import worker from '@ohos.worker';
import { WinsleiLogManager } from '@winslei/winsleilog'

const TAG = 'WorkerPort'

// 创建worker线程中与主线程通信的对象
const workerPort = worker.workerPort

// worker线程接收主线程信息
workerPort.onmessage = ((event) => {
  WinsleiLogManager.hilogIWithTag(TAG, `workerInstance onmessage event: ${JSON.stringify(event)}`)

  // worker线程向主线程发送信息
  workerPort.postMessage("123")
})

// worker线程发生error的回调
workerPort.onerror = (event) => {
  WinsleiLogManager.hilogIWithTag(TAG, `workerInstance onerror event: ${JSON.stringify(event)}`)
}